import time
import sys

class A():
    def __init__(self):
        self.n = 10
    
    def __enter__(self):
        print "CONTEXT ENTER"
        return self.next()
    
    def __exit__(self, e_t, e_v, t_b):
        print e_t, e_v, t_b
        print t_b
        print "CONTEXT EXIT"
        
    def next(self):
        for i in xrange(10):
            yield i

def f():        
    with A() as a_iter:
        for i in xrange(10):
            a = 1 # redudent statments
            b = 2
            print "HERE at f()"
            sys.stdout.flush()
            time.sleep(1)
            yield a_iter.next()

def test():
    ff = f()
    for i in xrange(10):
        print ff.next()
        sys.stdout.flush()
        import time
        time.sleep(1)
        
def test1():
    with A() as a_iter:
        for i in xrange(10):
            print a_iter.next()
            sys.stdout.flush()
            import time
            time.sleep(1)


if __name__ == "__main__":
    print "Test"
    test()
    print "Test1"
    test1()
    
